#should install opencv first

sudo apt-get install -y --no-install-recommends build-essential cmake git libgoogle-glog-dev libprotobuf-dev protobuf-compiler python-dev python-pip libopenmpi-dev openmpi-bin openmpi-doc libleveldb-dev liblmdb-dev libpython-dev libsnappy-dev python-numpy python-protobuf libgflags-dev

pip install pyyaml typing future hypothesis six
pip install --upgrade protobuf

git clone --recursive https://github.com/pytorch/pytorch.git
cd pytorch
git submodule update --init

rm -rf build
mkdir build
cd build

cmake -DCUDA_USE_STATIC_CUDA_RUNTIME=OFF ..
make 
sudo make install
sudo ldconfig

gedit ~/.bashrc
#add '/usr/local/lib:' to the end of line 'export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib64:'
source ~/.bashrc

#reboot

echo "complete install caffe2, you can delete 'pytorch' folder"

cd ~
python -c 'from caffe2.python import core' 2>/dev/null && echo "Success" || echo "Failure"
python -c 'from caffe2.python import workspace; print(workspace.NumCudaDevices())'
